<!DOCTYPE html>
<html lang="en">
<!--
	作者：梁家宝
	时间：2019-05-29
	描述：用户管理表的添查修改
-->
	<head>
		<meta charset="UTF-8">
		<title>用户管理</title>
		<link rel="stylesheet" href="../../../js/bower_components/bootstrap/dist/css/bootstrap.min.css">
		<link rel="stylesheet" href="../../../js/bower_components/bootstrap-select/dist/css/bootstrap-select.min.css">
		<link rel="stylesheet" href="../../../js/bower_components/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.min.css">
		<link rel="stylesheet" href="../../../js/bower_components/bootstrap-table/dist/bootstrap-table.min.css">
		<link rel="stylesheet" href="../../../js/bower_components/bootstrap-treeview/dist/bootstrap-treeview.min.css">

		<script src="../../../js/bower_components/jquery/dist/jquery.min.js"></script>
		<script src="../../../js/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="../../../js/bower_components/bootbox.min.js"></script>
		<script src="../../../js/bower_components/bootstrap-select/js/bootstrap-select.js"></script>
		<script src="../../../js/bower_components/bootstrap-switch/dist/js/bootstrap-switch.min.js"></script>
		<script src="../../../js/bower_components/bootstrap-table/dist/bootstrap-table.min.js"></script>
		<script src="../../../js/bower_components/bootstrap-table/dist/locale/bootstrap-table-zh-CN.js"></script>

		<script src="../../../js/bower_components/bootstrap-treeview/dist/bootstrap-treeview.min.js"></script>
		<script src="../../../js/bower_components/jquery-form-validator/form-validator/jquery.form-validator.min.js"></script>
		<script src="../../../js/bower_components/moment/min/moment-with-locales.min.js"></script>
		<script>
			var temp_uid = 0;
			$(function() {
				//下拉框是否启用进行绑定
				SelUisbegin();
				SelUisbegin1();
				$.ajax({
					type: "get",
					url: "http://127.0.0.1:8080/getAll1",
					dataType: "json",
					contentType: "application/json;charset=utf-8",
					success: function(data) {
						console.log(data);
						console.log(data.data.list)
						CreateUserTable(data.data.list)
					}
				});
				//CreateUserTable("");
				//新增数据
				$("#butAdd").click(function() {
					alert("ssss")
					$("#divData").modal();
				});
				//保存数据
				$("#btnSave").click(function() {
					var uid = $("#txtUseruid").val();
					var uname = $("#txtUserName1").val();
					var uisbegin = $("#seluisbegin1").selectpicker('val');
					var passwd = $("#txtUserPasswd").val();
					var phonenb = $("#txtUserPhonenb").val();
					var email = $("#txtUserEmail").val();
					var createt = $("#txtUserCreatet").val();
					var updatet = $("#txtUserUpdatet").val();
					var createp = $("#txtUserCreatep").val();
					var updatep = $("#txtUserUpdatep").val();
					var sex = $("#txtUserSex").val();
					var juris = $("#txtUserJuris").val();
					var head = $("#txtUserHead").val();
					var office = $("#txtUserOffice").val();
					var rid = $("#txtUserRid").val();
					var cid = $("#txtUserCid").val();
					alert(uid + "--" + uname + "--" + uisbegin)
					var str = '{"cid": '+cid+',"createp": "'+createp +'","createt": "'+createt+'","email": "'+email+'","head": "'+head+'","juris": "'+juris+'","office": "'+office+'","passwd": "'+passwd+'",';
					str+='"phonenb": '+phonenb+',"rid": '+rid+',"sex": "'+sex+'","uid": '+uid+',"uisbegin": "'+uisbegin+'","uname": "'+uname+'","updatep": "'+updatep+'","updatet": "'+updatet+'"}';
					console.log(str);
					$.ajax({
						type: "put",
						url: "http://127.0.0.1:8080/addUid",
						data: str,
						dataType: "json",
						contentType: "application/json;charset=utf-8",
						success: function(data) {
							console.log(data);
							if(data == 1) {
								$.ajax({
									type: "get",
									url: "http://127.0.0.1:8080/getAll1",
									dataType: "json",
									contentType: "application/json;charset=utf-8",
									success: function(data) {
										CreateUserTable(data.data.list);
										emptyData();
									}
								});
							}

						}
					});
				})
				//删除数据
				$("#butDel").click(function() {
					var uid = temp_uid;
					alert("确认删除角色的主键是：" + uid)
					$.ajax({
						type: "get",
						url: "http://127.0.0.1:8080/delUid",
						data: "uid=" + uid,
						dataType: "json",
						contentType: "application/json;charset=utf-8",
						success: function(data) {
							alert(uid);
							if(data == 1) {
								$.ajax({
									type: "get",
									url: "http://127.0.0.1:8080/getAll1",
									dataType: "json",
									contentType: "application/json;charset=utf-8",
									success: function(data) {
										CreateUserTable(data.data.list)
									}
								});
							} else {
								alert("删除失败")
							}
						}
					});
				});
				//修改数据之前获取数据的方法
				$("#butEdit").click(function() {
					var uid = temp_uid;
					if(uid > 0) {
						$.ajax({
							type: "get",
							url: "http://127.0.0.1:8080/getAll",
							data: "uid=" + uid,
							dataType: "json",
							contentType: "application/json;charset=utf-8",
							success: function(data) {
								alert(data);
								if(data != null) {
									$("#divData").modal();
									$("#txtUseruid").val(data.uid);
									$("#txtUseruid").attr("readonly", "true");
									$("#txtUserName1").val(data.uname);
									console.log()
									$("#seluisbegin1").selectpicker('val', data.uibegin);
								} else {
									alert("删除失败")
								}
							}
						});
					}
				})
			});

			//给下拉框绑定动态数据
			function SelUisbegin() {
				$("#seluisbegin").empty();
				$.ajax({
					type: "get",
					url: "http://127.0.0.1:8080/getUIsBegin",
					dataType: "json",
					success: function(data) {
						console.log(data.list);
						//绑定数据
						$.each(data, function(i, n) {
							$("#seluisbegin").append("<option value='" + n.uisbegin + "'>" + n.uisbegin + "</option>");
						});
						//刷新下拉框
						$("#seluisbegin").selectpicker("refresh");
					}
				});
			}

			//对角色列表加载动态数据
			function CreateUserTable(data) {
				//			console.log("进入绑定事件"+data)
				$("#tabUser").bootstrapTable("destroy");
				$("#tabUser").bootstrapTable({
					loadMsg: "数据正在加载中....",
					uniqueId: "uid", //绑定列表主键（数据库主键）
					pageSize: 5,
					pagination: true,
					idFied: "uid",
					onClickRow: function(row) {
						alert(row.uid);
						temp_uid = row.uid;
					},
					data: data,
					columns: [{
						field: "uid",
						title: "用户主键"
					}, {
						field: "uname",
						title: "用户名称"
					}, {
						field: "uisbegin",
						title: "用户是否启用"
					}, {
						field: "passwd",
						title: "用户密码"
					}, {
						field: "phonenb",
						title: "用户手机号"
					}, {
						field: "email",
						title: "用户邮箱"
					}, {
						field: "createt",
						title: "创建时间"
					}, {
						field: "updatet",
						title: "更新时间"
					}, {
						field: "createp",
						title: "创建人"
					}, {
						field: "updatep",
						title: "更新人"
					}, {
						field: "sex",
						title: "性别"
					}, {
						field: "juris",
						title: "权限"
					}, {
						field: "head",
						title: "头像"
					}, {
						field: "office",
						title: "科室"
					}, {
						field: "rid",
						title: "角色"
					}, {
						field: "cid",
						title: "所在公司"
					}]
				});
				//给下拉框绑定json数据
			}

			function SelUisbegin1() {
				$("#seluisbegin").empty();
				$.ajax({
					type: "get",
					url: "../json/sysUser.json",
					dataType: "json",
					success: function(data) {
						console.log(data.list);
						//绑定数据
						$.each(data, function(i, n) {
							$("#seluisbegin1").append("<option value='" + n.uisbegin + "'>" + n.uisbegin + "</option>");
						});
						//刷新下拉框
						$("#seluisbegin1").selectpicker("refresh");
					}
				});
			}
			//清空表单数据
			function emptyData() {
				$("#txtUseruid").val("");
			 	$("#txtUserName1").val("");
				$("#seluisbegin1").selectpicker("");
				$("#txtUserPasswd").val("");
				$("#txtUserPhonenb").val("");
				$("#txtUserEmail").val("");
				$("#txtUserCreatet").val("");
				$("#txtUserUpdatet").val("");
				$("#txtUserCreatep").val("");
				$("#txtUserUpdatep").val("");
				$("#txtUserSex").val("");
				$("#txtUserJuris").val("");
				$("#txtUserHead").val("");
				$("#txtUserOffice").val("");
				$("#txtUserRid").val("");
				$("#txtUserCid").val("");
			}
		</script>

	</head>

	<body>
		<div class="container-fluid">
			<!--查询区域-->
			<div class="row col-md-10">
				<div class="form-inline">
					<div class="form-group">
						<label class="control-label" for="txtUserName">用户名称</label>
						<input class="form-control" id="txtUserName" />
					</div>
					<div class="form-group">
						<label class="control-label">用户是否启用</label>
						<select id="seluisbegin"></select>
					</div>
					<div class="form-group">
						<button type="button" class="btn btn-primary">查询</button>
					</div>
				</div>
			</div>
			<br /><br /><br />
			<!--功能区域-->
			<div class="row col-md-10">
				<div>
					<button type="button" id="butAdd" class="btn btn-success">新增</button>
					<button type="button" id="butEdit" class="btn btn-info">修改</button>
					<button type="button" id="butDel" class="btn btn-danger">删除</button>
				</div>
			</div>
			<br /><br /><br />
			<!--列表区域-->
			<div class="row col-md-10">
				<table id="tabUser"></table>
			</div>
			<!--表单区域-->
			<div class="modal fade" id="divData" tabindex="1">
				<div class="modal-dialog" style="width: 500px;">
					<div class="modal-content">
						<div class="modal-header">
							<h4 class="modal-title">新增用户信息</h4>
						</div>
						<div class="modal-body form-inline">
							<div class="form-group">
								<label class="control-label">用户主键</label>
								<input type="number" maxlength="20" class="from-control" id="txtUseruid" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">用户名称</label>
								<input type="text" maxlength="20" class="from-control" id="txtUserName1" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">是否启用</label>
								<select id="seluisbegin1">

								</select>
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">用户密码</label>
								<input type="text" maxlength="20" class="from-control" id="txtUserPasswd" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">用户手机号</label>
								<input type="text" maxlength="20" class="from-control" id="txtUserPhonenb" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">用户邮件</label>
								<input type="text" maxlength="20" class="from-control" id="txtUserEmail" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">创建时间</label>
								<input type="date" maxlength="20" class="from-control" id="txtUserCreatet" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">更新时间</label>
								<input type="date" maxlength="20" class="from-control" id="txtUserUpdatet" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">创建人</label>
								<input type="text" maxlength="20" class="from-control" id="txtUserCreatep" />
							</div>
							<br /> <br />
							<div class="form-group">
								<label class="control-label">更新人</label>
								<input type="text" maxlength="20" class="from-control" id="txtUserUpdatep" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">性别</label>
								<input type="text" maxlength="20" class="from-control" id="txtUserSex" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">权限</label>
								<input type="text" maxlength="20" class="from-control" id="txtUserJuris" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">头像</label>
								<input type="text" maxlength="20" class="from-control" id="txtUserHead" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">科室</label>
								<input type="text" maxlength="20" class="from-control" id="txtUserOffice" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">角色</label>
								<input type="text" maxlength="20" class="from-control" id="txtUserRid" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">所在公司</label>
								<input type="text" maxlength="20" class="from-control" id="txtUserCid" />
							</div>
							<br /><br />
							<div class="modal-footer">
								<button type="button" class="btn btn-success" id="btnSave" data-dismiss="modal">保存</button>
								<button type="button" class="btn btn-primary" id="btnClose" data-dismiss="modal">取消</button>
							</div>
							<br />
						</div>
					</div>
				</div>
			</div>
		</div>

	</body>

</html>